package com.weimin.mqtt.server.model;

import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.Set;
import java.util.function.Function;

@Data
@NoArgsConstructor
public class MqttSession {

    /**
     * mqtt连接的用户名
     */
    private String username;
    /**
     * mqtt连接的密码
     */
    private byte[] password;
    /**
     * mqtt连接的ip
     */
    private String ip;
    /**
     * 设备唯一标识
     */
    private String clientId;
    /**
     * 设备对应的通信连接通道ID 即netty channel id
     */
    private String connectId;
    /**
     * 给设备发送消息的回调函数
     */
    private Function<MqttSessionPublishMessage, Boolean> publisher;
    /**
     * 设备最后刷新时间，也就是最后一次给paas发送数据的时间
     */
    private Long refreshTime;
    /**
     * 订阅消息
     */
    private Set<String> subTopics;
    /**
     * 一些额外的数据，用于扩展
     */
    private Object data;

    public MqttSession(String username, byte[] password, String ip, String clientId, String connectId, Function<MqttSessionPublishMessage, Boolean> publisher) {
        this.username = username;
        this.password = password;
        this.ip = ip;
        this.clientId = clientId;
        this.connectId = connectId;
        this.publisher = publisher;
    }
}
